Standarise the handling of dicts and data frames across prob methods - #1128
Standarise the handling of dicts and data frames across prob methods#1128GregoryAshton wants to merge 2 commits into
Conversation
Previously, ln_prob adding conditional catches to handle dictionaries and data drames properly. But, this wasn't mirrored across related methods. This adds that mirroring
There was a problem hiding this comment.
Pull request overview
This pull request standardizes how PriorDict/ConditionalPriorDict probability methods infer the array backend (xp) when samples are provided as either dictionaries or DataFrame-like objects, aligning behavior across related probability APIs.
Changes:
- Updates
prob(and conditional variants) to inferxpcorrectly whensampleis adictvs. a DataFrame-like object. - Mirrors previously-added DataFrame/dict handling patterns across additional probability methods to keep the API consistent.
Suppressed comments (2)
bilby/core/prior/dict.py:848
- Same
xpinference pattern as above: treating any non-dictsampleas a DataFrame and readingsample.valuescan produce confusing errors for other mapping/array-like inputs.array_module(sample)already covers dicts and pandas objects, so it’s safer and simpler.
if xp is None and isinstance(sample, dict):
xp = array_module(sample.values())
elif xp is None:
# assume input is a dataframe
xp = array_module(sample.values)
bilby/core/prior/dict.py:879
- Same
xpinference issue here: the current branch assumes any non-dictsampleis a DataFrame and accessessample.values. Usingarray_module(sample)avoids relying on a specific attribute and matchesarray_module’s built-in handling for dict/pandas inputs.
if xp is None and isinstance(sample, dict):
xp = array_module(sample.values())
elif xp is None:
# assume input is a dataframe
xp = array_module(sample.values)
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if xp is None and isinstance(sample, dict): | ||
| xp = array_module(sample.values()) | ||
| elif xp is None: | ||
| # assume input is a dataframe | ||
| xp = array_module(sample.values) |
| elif xp is None: | ||
| # assume input is a dataframe | ||
| xp = array_module(sample.values) |
| if xp is None and isinstance(sample, dict): | ||
| xp = array_module(sample.values()) | ||
| elif xp is None: | ||
| # assume input is a dataframe | ||
| xp = array_module(sample.values) |
Caude SummaryFixes a regression introduced in 612c46b ("Support non-numpy array backends (#886)"), which added Fixed (
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1128 +/- ##
==========================================
+ Coverage 72.12% 72.14% +0.02%
==========================================
Files 86 86
Lines 15371 15376 +5
Branches 2333 2337 +4
==========================================
+ Hits 11086 11093 +7
+ Misses 3578 3576 -2
Partials 707 707
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Previously, ln_prob adding conditional catches to handle dictionaries and data drames properly. But, this wasn't mirrored across related methods. This adds that mirroring